trivial-httpd: prepend timestamp in log file
authorJonathan Lebon <jlebon@redhat.com>
Thu, 18 Aug 2016 16:10:20 +0000 (12:10 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 31 Aug 2016 16:52:12 +0000 (16:52 +0000)
I've found this useful when monitoring multiple logs at the same time to
test the upcoming content & meta URL splitting.

Closes: #469
Approved by: cgwalters

src/ostree/ot-builtin-trivial-httpd.c

index 30c593c20c8b5327e951c92de157ec47bb55e51e..88a1a74b13b9dd119696435538911eba5ab96f3d 100644 (file)
@@ -77,9 +77,15 @@ httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...)
   if (!httpd->log)
     return;
 
-  str = g_string_new (NULL);
+  {
+    g_autoptr(GDateTime) now = g_date_time_new_now_local ();
+    g_autofree char *timestamp = g_date_time_format (now, "%F %T");
+    str = g_string_new (timestamp);
+    g_string_append_printf (str, ".%06d - ", g_date_time_get_microsecond (now));
+  }
+
   va_start (args, format);
-  g_string_vprintf (str, format, args);
+  g_string_append_vprintf (str, format, args);
   va_end (args);
 
   g_output_stream_write_all (httpd->log, str->str, str->len, &written, NULL, NULL);